package com.huike.controller;

import com.huike.core.controller.BaseController;
import com.huike.core.domain.R;
import com.huike.core.page.TableDataInfo;

import com.huike.dto.CourseDto;
import com.huike.dto.domain.Course;
import com.huike.service.CourseService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clues/course")
@Slf4j
public class CourseController extends BaseController {
    @Autowired
    private CourseService courseService;

    /**
     * 查询课程管理列表
     */
    @PreAuthorize("@ss.hasPermi('clues:course:list')")
    @GetMapping("/list")
    public TableDataInfo list(Course course) {
        startPage();
        List<Course> list = courseService.selectTbCourseList(course);
        return getDataTable(list);
    }

    /**
     * 新增课程
     */
    @PostMapping
    public R insertCourse(@RequestBody Course course){
        log.info("insertCourse:{}", course);
        courseService.insert(course);
       return R.ok();
    }


    /**
     * 修改课程
     */
    @PutMapping
    public R updateCourse(@RequestBody CourseDto dto){
        log.info("updateCourse:{}", dto);
        courseService.updateCourse(dto);
        return R.ok();
    }

    /**
     *查询课程
     */
    @GetMapping("/{id}")
    public R<Course> selectCourseById(@PathVariable Long id){
     Course co= courseService.selectById(id);
        return R.ok(co);
    }

    /**
     * 批量删除课程
     */
    @DeleteMapping("/{ids}")
    public R deleteCourseByIds(@PathVariable Long[] ids){
        return R.ok(courseService.deleteCourseByIds(ids));
    }
}
